package com.ywh.util;

import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.WorkbookSettings;

public class ExcelUtil {

	/**
	 * 功能描述
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			WorkbookSettings workbookSettings = new WorkbookSettings();
			workbookSettings.setEncoding("utf8");
			Workbook wb = Workbook.getWorkbook(new File(
					"d:\\上古服务器端中文字整理CH_TH.xls"));
			String output = "d:\\resource.properties";
			Sheet[] sheets = wb.getSheets();
			// 从第三个sheet开始处理，最后一个sheet不处理
			PrintWriter pw = new PrintWriter(new FileWriter(output));
			for (int i = 2; i < sheets.length - 1; i++) {
				Sheet sheet = sheets[i];
				pw.println("#===============" + sheet.getName()
						+ "====================");
				System.out.println("===============" + sheet.getName()
						+ "====================");
				int rows = sheet.getRows();
				// 从第三行开始输出
				for (int j = 2; j < rows; j++) {
					Cell[] cells = sheet.getRow(j);
					if (cells == null || cells.length == 0) {
						pw.println();
						System.out.println();
					} else if (cells.length < 3) { // 小于三列的都不输出
					// for(int k=0; k<cells.length; k++) {
					// System.out.print(cells[k].getContents()+"\t");
					// }
					// System.out.println();
					} else if (cells[1].getContents().trim().length() > 1) { // key为空的行都不输出
						pw.println(cells[1].getContents() + "="
								+ cells[2].getContents());
						System.out.println(cells[1].getContents() + "="
								+ cells[2].getContents());
					}
				}
			}
			pw.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
